履歴: 電気回路/HDL/SystemC の導入
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 17 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2022/12/12 23:32:22 | 電気回路/HDL/SystemC の導入 最新版 | 18,061 | +1 | -1 | 表示 | 差分 | — |
| 2022/12/12 23:32:22 | 電気回路/HDL/SystemC の導入 | 18,067 | +0 | -1 | 表示 | 差分 | 選択 |
| 2022/11/2 0:57:59 | 電気回路/HDL/SystemC の導入 | 18,068 | +1 | -0 | 表示 | 差分 | 選択 |
| 2021/9/28 2:35:29 | 電気回路/HDL/SystemC の導入 | 18,067 | +0 | -9 | 表示 | 差分 | 選択 |
| 2021/9/27 13:17:21 | 電気回路/HDL/SystemC の導入 | 18,313 | +9 | -0 | 表示 | 差分 | 選択 |
| 2021/7/25 1:43:25 | 電気回路/HDL/SystemC の導入 | 18,067 | +0 | -9 | 表示 | 差分 | 選択 |
| 2021/7/24 14:30:10 | 電気回路/HDL/SystemC の導入 | 18,462 | +9 | -0 | 表示 | 差分 | 選択 |
| 2013/1/4 1:04:25 | 電気回路/HDL/SystemC の導入 | 18,067 | +0 | -8 | 表示 | 差分 | 選択 |
| 2013/1/3 15:37:12 | 電気回路/HDL/SystemC の導入 | 18,203 | +8 | -0 | 表示 | 差分 | 選択 |
| 2010/10/29 16:07:42 | 電気回路/HDL/SystemC の導入 | 18,067 | +5 | -0 | 表示 | 差分 | 選択 |
| 2010/10/29 16:07:42 | 電気回路/HDL/SystemC の導入 | 17,997 | +2 | -2 | 表示 | 差分 | 選択 |
| 2010/10/29 16:07:42 | 電気回路/HDL/SystemC の導入 | 17,973 | +5 | -1 | 表示 | 差分 | 選択 |
| 2010/10/29 16:07:42 | 電気回路/HDL/SystemC の導入 | 17,855 | +16 | -12 | 表示 | 差分 | 選択 |
| 2010/10/29 16:07:42 | 電気回路/HDL/SystemC の導入 | 17,722 | +2 | -1 | 表示 | 表示中 | 選択 |
| 2010/10/29 16:07:42 | 電気回路/HDL/SystemC の導入 | 17,664 | +23 | -54 | 表示 | 差分 | 選択 |
| 2010/10/29 11:46:07 | 電気回路/HDL/SystemC の導入 | 19,172 | +255 | -5 | 表示 | 差分 | 選択 |
| 2010/10/29 6:19:02 | 電気回路/HDL/SystemC の導入 | 12,241 | — | — | 表示 | — | 基準 |
基準: 電気回路/HDL/SystemC の導入 (2010/10/29 6:19:02) → 比較: 電気回路/HDL/SystemC の導入 (2010/10/29 16:07:42)
@@ -2,13 +2,30 @@
#contents
+* Verilator で SystemC によるテストベンチを動かす [#l08686db]
+
+Verilator を使うと Verilog モジュールを SystemC に変換し、
+同じく SystemC で書いたテストベンチを用いて検証することが可能、
+とのことでやってみました。
+
+続きとして、Verilator でカバレッジ測定を行ってみた結果を [[電気回路/HDL/SystemPerl の導入]] にまとめました。
+
* SystemC のインストール [#e287567b]
+SystemC の実体は C++ 上のクラスライブラリです。
+
+Verilator で SystemC ライブラリ互換のコードに変換された verilog モジュールは、
+コンパイル時にライブラリのインクルードファイルが必要となり、また、
+実行するにはライブラリとリンクする必要があります。
+
+そこで、SystemC のインストールを行うことにしました。
+
SystemC は http://www.systemc.org/downloads/lrm から無償で落とせるのですが、
ユーザー登録が必要でした。
いろいろ落としてきましたが、ここでは systemc-2.2.0 のみインストールします。
+ LANG:console
$ cd systemc/
$ ls
@@ -223,7 +240,6 @@
config.status: creating examples/sysc/2.1/specialized_signals/Makefile
config.status: executing depfiles commands
- osamu@takeuchi-thnkpd ~/systemc/systemc-2.2.0/objdir
$ make
...
@@ -252,6 +268,7 @@
エラー出ました。
+ LANG:console
../../../../src/sysc/utils/sc_utils_ids.cpp
110: error: ‘getenv’ is not a member of ‘std’
111: error: ‘strcmp’ was not declared in this scope
@@ -277,9 +294,9 @@
...
-これでインストール終了。
+インストール終了。
-えと、何ができるようになったんでしょう(笑
+えと、これで何ができるようになったんでしょう?(笑
* 正しくインストールされたかをチェックする [#u8e43a39]
@@ -350,6 +367,8 @@
いじるのは、~
include/sysc/kernel/sc_constants.h
+で、
+
LANG:CPP
const int SC_DEFAULT_STACK_SIZE = 0x10000;
@@ -361,7 +380,7 @@
としました。
さらに、上記 URL で指示されているとおり
-make pthreads_check も行います。
+make pthreads_check もやってみました。
LANG:console
$ make clean
@@ -382,12 +401,213 @@
特に初回の make check にかなりの時間がかかるので、
その間に http://homepage3.nifty.com/hdl_design/systemc.htm でお勉強。
-途中でキー入力を求めるテストなんかもあって、
+途中でキー入力を求めるテストもあって、
ちょっとどうかな、とも思いますが、
エラー無く通りました。
-まだ使い方は何にも分かってません(汗
+これで SystemC ライブラリが ~/systemc/systemc-2.2.0/ にできあがりました。
+* SystemC を使って Verilator テスト [#tf57b5e2]
+
+http://www10.atwiki.jp/bambooflow/pages/53.html
+
+http://www.applistar.com/technologies/
+
+http://homepage3.nifty.com/hdl_design/systemc.htm
+
+あたりをちらちら見てみましたが、細かい文法はともかく、
+まずはテストベンチを動かしてみたい。
+
+そこで、最低限の約束事だけ頭に入れ簡単なテストベンチを作り、
+Verilator 変換した verilog モジュールとともに動かしてみました。
+
+流れ的には [[電気回路/HDL/Verilator の導入(C++モード)]] の続きになります。
+
+bin2bcd_sc.cpp
+ LANG:cpp
+ #include "Vbin2bcd.h"
+ int sc_main(int argc, char **argv) {
+
+ Verilated::commandArgs(argc, argv);
+
+ sc_clock clk ("clk", 10);
+ sc_signal<bool> rst, start, busy;
+ sc_signal<uint32_t> bin;
+ sc_signal<uint32_t> bcd;
+
+ Vbin2bcd top("top");
+ top.clk(clk);
+
+ top.rst(rst);
+ top.start(start);
+ top.busy(busy);
+ top.bin(bin);
+ top.bcd(bcd);
+
+ // 検証開始
+ rst = 1;
+ start = 0;
+ bin = 123;
+
+ sc_start(100, SC_NS);
+ rst = 0;
+
+ sc_start(100, SC_NS);
+ start = 1;
+
+ sc_start(10, SC_NS);
+ start = 0;
+
+ sc_start(10, SC_NS);
+ while(busy)
+ sc_start(10, SC_NS);
+
+ cout << hex << showbase << bcd << endl;
+
+ exit(0);
+ }
+
+を用意して、
+
+ LANG:console
+ $ rm obj_dir/*
+
+ $ verilator -sc -Wno-lint bin2bcd.v --exe bin2bcd_sc.cpp
+ %Error: Need $SYSTEMC in environment
+ Probably System-C isn't installed, see http://www.systemc.org
+ %Error: Command Failed verilator_bin -sc -Wno-lint bin2bcd.
+ v --exe bin2bcd_sc.cpp
+
+ $ export SYSTEMC=~/systemc/systemc-2.2.0/
+
+ $ verilator -sc -Wno-lint bin2bcd.v --exe bin2bcd_sc.cpp
+
+ $ cd obj_dir
+
+ $ make -j -f Vbin2bcd.mk Vbin2bcd
+ g++ -I. -MMD -I/home/osamu/verilator-3.804/include -I/home/osamu/verilator-3.80
+ 4/include/vltstd -DVL_PRINTF=printf -DVM_TRACE=0 -DVM_COVERAGE=0 -I/home/
+ osamu/systemc/systemc-2.2.0//include -c -o bin2bcd_sc.o ../bin2bcd_sc.cpp
+ g++ -L/home/osamu/systemc/systemc-2.2.0//lib-cygwin bin2bcd_sc.o verilated.o
+ Vbin2bcd__ALL.a -o Vbin2bcd -lm -lstdc++ -lsystemc 2>&1 | c++filt
+
+ $ ls
+ Vbin2bcd.cpp Vbin2bcd__ALLcls.o Vbin2bcd__verFiles.dat
+ Vbin2bcd.exe* Vbin2bcd__ALLsup.cpp Vbin2bcd_classes.mk
+ Vbin2bcd.h Vbin2bcd__ALLsup.d bin2bcd_sc.d
+ Vbin2bcd.mk Vbin2bcd__ALLsup.o bin2bcd_sc.o
+ Vbin2bcd__ALL.a Vbin2bcd__Syms.cpp verilated.d
+ Vbin2bcd__ALLcls.cpp Vbin2bcd__Syms.h verilated.o
+ Vbin2bcd__ALLcls.d Vbin2bcd__ver.d
+
+ $ ./Vbin2bcd.exe
+
+ SystemC 2.2.0 --- Oct 29 2010 15:47:29
+ Copyright (c) 1996-2006 by all Contributors
+ ALL RIGHTS RESERVED
+
+ Info: (I804) /IEEE_Std_1666/deprecated:
+ sc_clock(const char*, double, double, double, bool)
+ is deprecated use a form that includes sc_time or
+ sc_time_unit
+ 0x123
+
+ということで、ちゃんと動いているようです。
+
+SystemC の良いところは、テストベンチ中で C++ の機能を 100% 生かせることなので、
+テスト部分を少し変更して、以下のようにしてみました。
+
+ LANG:cpp
+ #include "Vbin2bcd.h"
+ int sc_main(int argc, char **argv) {
+
+ Verilated::commandArgs(argc, argv);
+
+ sc_clock clk ("clk", 10, SC_NS);
+ sc_signal<bool> rst, start, busy;
+ sc_signal<uint32_t> bin;
+ sc_signal<uint32_t> bcd;
+
+ Vbin2bcd top("top");
+
+ top.clk(clk);
+ top.rst(rst);
+ top.start(start);
+ top.busy(busy);
+ top.bin(bin);
+ top.bcd(bcd);
+
+ // 検証開始
+ rst = 1;
+ start = 0;
+
+ sc_start(100, SC_NS);
+ rst = 0;
+ sc_start(100, SC_NS);
+
+ for(int i=0; i<1024; i++) {
+
+ bin = i;
+
+ start = 1;
+ sc_start(10, SC_NS);
+ start = 0;
+
+ sc_start(10, SC_NS);
+ while(busy)
+ sc_start(10, SC_NS);
+
+ std::ostringstream os_bin;
+ std::ostringstream os_dec;
+
+ os_bin << dec << i; // 元の数値を10進数で表したもの
+ os_dec << hex << bcd; // 変換結果を16進数で表したもの
+ sc_assert(os_bin.str()==os_dec.str()); // 等しいことを検証
+
+ sc_start(40, SC_NS);
+ }
+
+ cout << "done";
+
+ exit(0);
+ }
+
+同時に、clk の指定も上記 warning を元に直しました。
+
+ LANG:console
+ $ make -j -f Vbin2bcd.mk Vbin2bcd
+ g++ -I. -MMD -I/home/osamu/verilator-3.804/include -I/home/osamu/verilator-3.80
+ 4/include/vltstd -DVL_PRINTF=printf -DVM_TRACE=0 -DVM_COVERAGE=0 -I/home/
+ osamu/systemc/systemc-2.2.0//include -c -o bin2bcd_sc.o ../bin2bcd_sc.cpp
+ g++ -L/home/osamu/systemc/systemc-2.2.0//lib-cygwin bin2bcd_sc.o verilated.o
+ Vbin2bcd__ALL.a -o Vbin2bcd -lm -lstdc++ -lsystemc 2>&1 | c++filt
+
+ $ ./Vbin2bcd.exe
+
+ SystemC 2.2.0 --- Oct 29 2010 15:47:29
+ Copyright (c) 1996-2006 by all Contributors
+ ALL RIGHTS RESERVED
+ done
+
+うん、これはいいかも。
+
+verilog モジュールのテストを SystemC で書ければ、
+SystemVerilog + DPI-C でやっていたようなことを
+もっと簡単にできるのかも?~
+>> [[電気回路/HDL/ModelSim XE を使った SystemVerilog DPI-C テスト]]
+
+verilog では @(posedge clk); というような書き方で
+クロックエッジや任意信号の立ち上がり・立ち下がりを待つ
+遅延をテストベンチの任意箇所に書くことができたのですが、
+SystemC ではそういう遅延を書くやり方は無いみたいですかね?
+
+まだまだ勉強が必要そうです。
+
+こちらのサイトは例示が具体的で勉強になりますね。~
+http://systemcjapan.com/systemc_lang/systemc_introduction1.html
+
+続きとして、Verilator でカバレッジ測定を行ってみた結果を [[電気回路/HDL/SystemPerl の導入]] にまとめました。
+
* コメント [#y20166b2]
#article_kcaptcha